using System.Collections.Generic;
using UnityEngine;

public class BallFlightPlan
{
	public class FlightPlanStage
	{
		public GravityFlight flight = new GravityFlight();

		public float duration;

		public bool useUnityPhysics;
	}

	public int stageCount;

	public int activeStage;

	public List<FlightPlanStage> stages = new List<FlightPlanStage>();

	public Vector3 landingPos;

	public PlayerBase playerThatHitBall;

	public bool isServeBall;

	public bool active;

	public float timeScale = 1f;

	public float baseTimeScale = 1f;

	public float racketTimeScale = 1f;

	public float flightTime { get; protected set; }

	public FlightPlanStage reboundStage { get; set; }

	public float timeToLand { get; set; }

	public float totalTimeScale
	{
		get
		{
			return baseTimeScale * timeScale * racketTimeScale;
		}
	}

	public bool isActive
	{
		get
		{
			return ActiveStage() != null && active;
		}
	}

	public void Reset()
	{
		reboundStage = null;
		stageCount = 0;
		activeStage = 0;
		playerThatHitBall = null;
		isServeBall = false;
		flightTime = 0f;
		active = false;
		timeScale = 1f;
		baseTimeScale = 1f;
		racketTimeScale = 1f;
	}

	public void Start()
	{
		active = true;
	}

	public void Stop()
	{
		active = false;
	}

	public FlightPlanStage LastStage()
	{
		return stages[stageCount - 1];
	}

	public float GetTotalDuration()
	{
		float num = 0f;
		for (int i = 0; i < stageCount; i++)
		{
			FlightPlanStage flightPlanStage = stages[i];
			num += flightPlanStage.duration;
		}
		return num;
	}

	public float GetDurationTillStage(FlightPlanStage desiredStage)
	{
		float num = 0f;
		for (int i = 0; i < stageCount; i++)
		{
			FlightPlanStage flightPlanStage = stages[i];
			if (flightPlanStage == desiredStage)
			{
				break;
			}
			num += flightPlanStage.duration;
		}
		return num;
	}

	public FlightPlanStage AddStage()
	{
		stageCount++;
		if (stageCount >= stages.Count)
		{
			stages.Add(new FlightPlanStage());
		}
		return stages[stageCount - 1];
	}

	public FlightPlanStage ActiveStage()
	{
		if (activeStage >= stageCount)
		{
			return null;
		}
		return stages[activeStage];
	}

	public void Update(float deltaTime)
	{
		if (!active)
		{
			return;
		}
		FlightPlanStage flightPlanStage = ActiveStage();
		if (flightPlanStage == null)
		{
			return;
		}
		deltaTime *= totalTimeScale;
		flightTime += deltaTime;
		GravityFlight flight = flightPlanStage.flight;
		flight.timeOfFlight += deltaTime;
		if (flight.timeOfFlight >= flightPlanStage.duration)
		{
			activeStage++;
			FlightPlanStage flightPlanStage2 = ActiveStage();
			if (flightPlanStage2 != null)
			{
				flightPlanStage2.flight.timeOfFlight = flight.timeOfFlight - flightPlanStage.duration;
			}
		}
	}
}
